#include<iostream>
#include<algorithm>
using namespace std;

class Solution {
public:
    string reverseStr(string s, int k) 
    {
        int size = s.size();
        int begin = 0;
       
        while ((begin + 2 * k) < size)
        {

            reverse(s.begin() + begin, s.begin() + begin + k);
            begin += 2 * k;
        }
        if (size-begin < k)
        {
            reverse(s.begin()+begin, s.end());
        }
        else if (size-begin >= k && size-begin <= 2 * k)
        {
            reverse(s.begin()+begin, s.begin()+begin + k);
        }
        return s;
    }
};

